﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EPanShareSystem.BLL;
using EPanShareSystem.Model;

namespace EPanShareSystem.Web.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        BLL.UserManage bllUserManage = new UserManage();

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult CheckLogin(Sys_User userInfo)
        {
            string msg = string.Empty;
            bool flag = false;

            #region 数据验证
            if (string.IsNullOrEmpty(userInfo.userName))
            {
                msg = "用户名不能为空";

            }
            if (string.IsNullOrEmpty(userInfo.pwd))
            {
                msg = "密码不能为空";
            }
            #endregion

            var userModel = bllUserManage.GetUserInfo(userInfo.userName, userInfo.pwd);
            if (userModel != null)
            {
                //登录成功
                LoginContenxt.SetUserInfo(userModel);
                flag = true;
            }
            else
            {
                msg = "登录失败";
            }
            return Json(new { flag = flag, msg = msg }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 注销
        /// </summary>
        /// <returns></returns>
        public ActionResult LoginOut()
        {
            LoginContenxt.ClearUserInfo();
            return RedirectToAction("Index","Login");
        }




        /// <summary>
        /// IFrame页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Frame()
        {
            return View();
        }

    }
}
